<template>
	<el-dialog title="确认考试" :visible.sync="dialogVisible" width="640px">
		<el-descriptions class="margin-top" :column="2" size="small" border v-if="row.hasOwnProperty('id')">
			<el-descriptions-item :span="2">
				<template slot="label">考试名称</template>
				{{ row.name }}
			</el-descriptions-item>
			<el-descriptions-item :span="2">
				<template slot="label">考试时间</template>
				{{ row.startTime }} 至 {{ row.endTime }}
			</el-descriptions-item>
			<el-descriptions-item>
				<template slot="label">考试时长</template>
				{{ row.examDuration }} 分钟
			</el-descriptions-item>
			<el-descriptions-item>
				<template slot="label">考试总分</template>
				{{ toFixeds(row.testPaper.totalScore) }}
			</el-descriptions-item>
			<el-descriptions-item>
				<template slot="label">及格分</template>
				{{ toFixeds(row.passScore) }}
			</el-descriptions-item>
			<el-descriptions-item>
				<template slot="label">考试次数</template>
				{{ row.examMaxNum - row.overExamNum }} / {{ row.examMaxNum }}
			</el-descriptions-item>
			<el-descriptions-item :span="2">
				<template slot="label">考试须知</template>
				<b class="color-danger">{{ row.testInstructions || '无' }}</b>
			</el-descriptions-item>
		</el-descriptions>
		<span slot="footer" class="dialog-footer">
			<el-button @click="dialogVisible = false">取 消</el-button>
			<el-button type="primary" @click="handleExam()" :disabled="row.examMaxNum - row.overExamNum <= 0">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
export default {
	data() {
		return {
			dialogVisible: false,
			row: {}
		};
	},
	mounted() {
		this.$bus.$on('showDialogExamConfirm', (v) => {
			this.row = v;
			this.dialogVisible = true;
		});
	},
	beforeDestroy() {
		this.$bus.$off('showDialogExamConfirm');
	},
	methods: {
		async handleExam() {
			let res = await this.$store.dispatch('testExamGeneratePAPER', this.row.id);
			if (!res) return;
			this.dialogVisible = false;
			const URL = this.$router.resolve({
				name: 'examing',
				query: {
					id: this.row.id
				}
			});
			window.open(URL.href, '_blank');
		}
	}
};
</script>
<style scoped lang="scss"></style>
